<blockquote>
    <p>微信Oauth2授权</p>
    <footer>
        <p>公众号登录地址 <a href="" target="_blank"></a> </p>
        <p>需要在微信公众号配置网页授权域, 且必须是备案域名, 设置如下图。</p>
    </footer>
</blockquote>
<blockquote>
    <p>设置</p>
</blockquote>
<img src="debug/websq.png" style="max-width: 1000px;"/>
<pre class="code brush:java">
package com.acxy.idleegg;

import cn.jants.common.annotation.action.Controller;
import cn.jants.common.annotation.action.GET;
import cn.jants.common.annotation.service.Application;
import cn.jants.common.annotation.service.Autowired;
import cn.jants.common.bean.Log;
import cn.jants.common.utils.StrUtil;
import cn.jants.core.startup.JTomcat;
import cn.jants.plugin.tool.WxOauth2Tool;
import cn.jants.plugin.weixin.SnsApi;
import cn.jants.plugin.weixin.WxUserMap;
import cn.jants.restful.render.Json;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

/**
 * 微信授权Oauth2示例
 *
 * @author MrShun
 * @version 1.0
 */
@Application
@Controller
public class IdleEggApplication {

    @Autowired
    private HttpServletResponse response;

    /**
     * 超简单微信授权示例
     *
     * @param code 微信授权Code码
     * @throws IOException
     */
    @GET("/wx/oauth")
    public void wxOauthLogin(String code) throws IOException {
        WxOauth2Tool oauth2Tool = WxOauth2Tool.init("填写自己公众号appId", "填写自己公众号appSecret");
        //没有code则重新定向到微信oauth2
        if (StrUtil.isBlank(code)) {
            String oauth2Url = oauth2Tool.getOauth2Url(SnsApi.UserInfo);
            response.sendRedirect(oauth2Url);
        } else {
            WxUserMap userInfo = oauth2Tool.getUserInfo(code);
            Log.info("微信 UserInfo: {}", userInfo);
            //TODO 可以放入缓存, 也可以保存到数据库

            //将信息输出到页面
            Json.writeJson(userInfo, response);
        }
    }

    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        JTomcat.run(IdleEggApplication.class, 80, "/api");
    }
}
</pre>
<script type="text/javascript">
    $(function () {
        SyntaxHighlighter.highlight();
        $(".toolbar").remove();
    });
</script>